﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace CommonTools.Character
{
    public class Reg
    {
        /// <summary>
        /// 是座机号码
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public static bool IsTel(string input)
        {
            Regex r = new Regex(@"^0(([1-9]\d)|([3-9]\d{2}))\d{8}$");
            return r.IsMatch(input);
        }

        /// <summary>
        /// 是手机号码
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public static bool IsPhone(string input)
        {
            Regex r = new Regex(@"^[0-9]{11}$");
            return r.IsMatch(input);
        }

        /// <summary>
        /// 是否是日期格式
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>

        public static bool IsDateString(string str)
        {
            return Regex.IsMatch(str, @"(\d{4})-(\d{1,2})-(\d{1,2})");
        }

        /// <summary>
        /// 这个是判断是否是时间格式
        /// </summary>
        /// <param name="timeval"></param>
        /// <returns></returns>
        public static bool IsTime(string timeval)
        {
            return Regex.IsMatch(timeval, "^((([0-1]?[0-9])|(2[0-3])):([0-5]?[0-9])(:[0-5]?[0-9])?)$");
        }

        /// <summary>
        /// 是否是数字类型
        /// </summary>
        /// <param name="strNumber"></param>
        /// <returns></returns>
        public static bool IsNumber(string strNumber)
        {
            return new Regex(@"^([0-9])[0-9]*(\.\w*)?$").IsMatch(strNumber);
        }

        /// <summary>
        /// 是否是电子邮件格式
        /// </summary>
        /// <param name="strEmail"></param>
        /// <returns></returns>

        public static bool IsEmail(string strEmail)
        {
            return Regex.IsMatch(strEmail, @"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$");
        }

        /// <summary>
        /// 是否是安全的sql
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static bool IsSafeSqlString(string str)
        {
            return !Regex.IsMatch(str, @"[-|;|,|\/|\(|\)|\[|\]|\}|\{|%|@|\*|!|\']");
        }
    }
}
